home *** CD-ROM | disk | FTP | other *** search
- Path: nntp.teleport.com!sschaem
- From: sschaem@teleport.com (Stephan Schaem)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: PPC compilers
- Date: 8 Jan 1996 16:04:57 GMT
- Organization: Teleport - Portland's Public Access (503) 220-1016
- Message-ID: <4crfb9$djs@maureen.teleport.com>
- References: <john.hendrikx.40ka@grafix.xs4all.nl> <4b77tq$htp@serpens.rhein.de> <MQAQx*XOe@yaps.rhein.de> <4bqhnf$6g5@sunsystem5.informatik.tu-muenchen.de> <jasonb.820051107@cs.uwa.edu.au> <4c9i2l$h3i@sunsystem5.informatik.tu-muenchen.de> <4cf0ep$233@ra.i
- <4ck47h$g07@maureen.teleport.com> <jasonb.820919731@cs.uwa.edu.au> <4com6v$415@maureen.teleport.com> <jasonb.821098303@cs.uwa.edu.au>
- NNTP-Posting-Host: julie.teleport.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- Jason S Birch (jasonb@cs.uwa.edu.au) wrote:
- : sschaem@teleport.com (Stephan Schaem) writes:
-
- : >Jason S Birch (jasonb@cs.uwa.edu.au) wrote:
- : >: sschaem@teleport.com (Stephan Schaem) writes:
- : >: >Lars Duening (duening@ibr.cs.tu-bs.de) wrote:
- : >: >: If a have to access hardware registers (never had to so far), I will
- : >: >: not do this by direct pointers, but instead define a structure
- : >: >: representing them. This is then the only place where I have to worry
- : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- : >: >: about .c, .w and .l, everywhere else I can write
- : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- : >: >: 'chipregs->blt0con = *b++;' and let the compiler figure the rest out.
- : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- : >: >: HLLs win again here: the compiler will warn if *b is of the wrong
- : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- : >: >: type, and if I defined the structure wrong (your .w/.l example), I
- : ^^^^
- : >: >: just have to correct the structure, not the n statements where it is
- : >: >: used. And the compiler would even take care of bitshifts where
- : >: >: necessary.
-
- : >: > You let the compiler tell you AFTER you write your code about the type?
-
- : >: That's not what he said. He said the only place he has to worry about .c, .w
- : >: and .l is where he's defining his structures (although even then, it would be
- : >: extremely rare) and after that he can just use his new types, relying on the
- : >: compiler to give a warning if he's made a mistake.
-
- : > I dont think he can declare like this: chipregs.bltcon0 con0;
- : > So he will need so 'worry' about it when he declare con0, he will
- : > read ushort when peeking the structure (Like the asm coder) or
- : > maybe he typedefed ushort chipreg; and will use this instead.
- : > *b could be a pointer to float for all he cares, dont you think its
- : > wise to know what data your are manipulating so you can declare your
- : > variable correctly?!?!
-
- : Again: *If* he's trying to create a data type with certain
- : implementation-dependent size-requirements (such as in the bltcon0
- : case, assuming no headers to give us one) *then*, at that point in
- : time, he has to know the size of the type in order to define it
- : correctly. He stated that earlier - check what I've underlined.
-
- He said he would create a structure... not a new type.
- Now, tell me how he can forget that chipregs->bltcon0 is
- of type UWORD when he will declar *b and use *b (I guess you
- could forget what type are your variable, but personaly think its
- not to wise)
-
- I'm sorry again , I dont see how you can program not knowing
- the type of your variable when you use them? Is it a pointer to a
- string C string? a pointer to a P String? Should I mask the variable
- before I shift? etc...
-
- : However, once done, he can then safely create variables of that type
- : (the abstract one he's defined, which happens to be the right size) and
- : safely assign appropriate values to them, without having to worry if
- : the eventual assignments are implemented as a .c, .w, or .l. He can
-
- He defined a structure not a type... read what you underlined.
-
- move.type (a0),(a1) ... so what if type read .word or .chipreg
-
- In asm you are forced to write what your thinking in all its detail,
- this mean forced to know your variable type. Something you should do
- even in C.
-
- : safely rely on the compiler to produce the correct code, and warn him
- : if he's trying to assign an inappropriate value. *b must be a pointer
- : to the correct type that he's defined, and as he said, the compiler
- : will warn him if *b is the wrong type. That's all.
-
- I agree its a feature of the compiler, something you can rule out on
- assembler. I just desagree that its something to rely on to declare and
- forget.
-
- : >: He needs to know how he's defined it, yes - but not whether it turns into a .c,
- : >: .w, or .l. It could be written as a UCHAR, a LONG, or even typedef'd to a
- : >: BILBY. Read it again.
-
- : > He needs to know how he declared it too... meaning he has to know when
- : > he write the code what is the type on bltcon0.. a uword or a BILBY (typdef
- : > for uword)... And if he as a few brain cell left he will remember that
- : > when he use the variable. EX when I declare float, long in a function
- : > I know wich is wich otherwise I might store a float temp result
- : > in a long and bang!
-
- : The question is not about whether you need to know if a variable is a
- : float or a long, since they are "abstract" types (and can be different
- : sizes on different machines). The question is whether you need to know
- : how many bits are in each, and what each bit means. In assembler, you
- : do need to know the former, and occasionally the latter.
-
- When you program in C... on what basis do you select your variable type?
- Do you limit yourself to int/float? for all integer work you use int,
- and real you use float?
-
- In C or asm I choose type according the the min range they hold.
- I cant imagine choosing a type for my operation without knowing the
- type range.
-
- : >: > Yea, I agree... move.w (ax)+,(a1)+ just mean : "Copy 2 bytes from a0 to
- : >: > a1, and increment both address by 2"
- : >: > In C the equivalent to move.? (a0)+,(a1)+ is
- : >: > A++ = B++;
- : >: > And that beying defined somewhere:
- : >: > ushort *A,*B;
-
- : >: That's only the C equivalent on certain platforms. C itself says nothing about
- : >: the actual size of its various types, other than a relative ordering.
-
- : > ANSI define very well the minimum size of its type.
-
- : It does *not* define that ushort is the same as two bytes, which is
- : what you are claiming above as being equivalent. It only guarantees
- : that char <= short <= long.
-
- It define that ushort can hold value from 0 to 65535... this is what I
- claim. ANSI C do define min range for the basic types, it would be
- unthinkable otherwise.
-
- : > Yes, thats very true... in asm you only have fixed type. But typedef is
- : > not really a part of the compiler but preprocessor, and could be easely
- : > integrated to an assembler.(But its not, so its hell when you modify
- : > structure)
-
- : >#typedef .w .chipreg
-
- : > move.chipreg (GLOBAL_x1,a4),(CHIPREG_bltcon0,a1)
-
- : typedef really is part of the compiler, not the preprocessor.
- : Unfortunately, given the notice C takes of typedefs you've made, it
- : may as well be part of the preprocessor. :-(
- : (ie. typedef xxx foo;
- : typedef xxx bar;
-
- : foo x;
- : bar y;
-
- : I would hope x = y to at least give a warning, even if they are
- : actually the same type.)
-
- I agree the above should at least give a warning.
-
- Stephan
-